package com.i_art_engineer.meigong.photo.filter.effect;

import android.content.Context;

import android.graphics.BitmapFactory;
import android.opengl.GLES20;

import com.i_art_engineer.meigong.R;
import com.i_art_engineer.meigong.util.ImageUtils;

public class LomofiFilter extends EffectFilter {
//    private int mContrastLocation;
//    private float mContrast=1f;     "uniform lowp float contrast;\n"+
    public static final String SHADER = "precision lowp float;\n" +
            " varying highp vec2 textureCoordinate;\n" +
            " \n" +
            " uniform sampler2D inputImageTexture;\n" +
            " uniform sampler2D inputImageTexture2; //blowout;\n" +
            " uniform sampler2D inputImageTexture3; //overlay;\n" +
            " uniform sampler2D inputImageTexture4; //map\n" +
            " \n" +
            " void main()\n" +
            " {\n" +
            "     \n" +
            "     vec4 texel = texture2D(inputImageTexture, textureCoordinate);\n" +
            "     vec3 bbTexel = texture2D(inputImageTexture2, textureCoordinate).rgb;\n" +
            "     \n" +
            "     texel.r = texture2D(inputImageTexture3, vec2(bbTexel.r, texel.r)).r;\n" +
            "     texel.g = texture2D(inputImageTexture3, vec2(bbTexel.g, texel.g)).g;\n" +
            "     texel.b = texture2D(inputImageTexture3, vec2(bbTexel.b, texel.b)).b;\n" +
            "     \n" +
            "     vec4 mapped;\n" +
            "     mapped.r = texture2D(inputImageTexture4, vec2(texel.r, .16666)).r;\n" +
            "     mapped.g = texture2D(inputImageTexture4, vec2(texel.g, .5)).g;\n" +
            "     mapped.b = texture2D(inputImageTexture4, vec2(texel.b, .83333)).b;\n" +
            "     mapped.a = 1.0;\n" +
            "     \n" +
            "     gl_FragColor = mapped;\n" +
            " }";

    // gl_FragColor = vec4(((mapped.rgb - vec3(0.5)) * contrast + vec3(0.5)), mapped.w)
//    public LomofiFilter() {
//        this(1f);
//    }
//
//    public LomofiFilter(float contrast) {
//        super(SHADER, 0);
////        mContrast = contrast;
//    }
//    public void setContrast(final float contrast) {
//        mContrast = contrast;
////        setFloat(mContrastLocation, mContrast);
//    }
//    @Override
//    public void onInit() {
//        super.onInit();
////        mContrastLocation = GLES20.glGetUniformLocation(getProgram(), "contrast");
//    }

//    @Override
//    public void onInitialized() {
//        super.onInitialized();
////        setContrast(mContrast);
//    }
   public LomofiFilter(Context context) {
//        super(SHADER, 2);
////        bitmaps[0] = BitmapFactory.decodeResource(context.getResources(), R.drawable.filter_lomo_map);
////        bitmaps[1] = BitmapFactory.decodeResource(context.getResources(), R.drawable.filter_vignette_map);
//       bitmaps[0] =  ImageUtils.readBitMap(context, R.drawable.filter_lomo_map);
//       bitmaps[1] =  ImageUtils.readBitMap(context, R.drawable.filter_vignette_map);
       super(SHADER, 3);
//        bitmaps[0] = BitmapFactory.decodeResource(context.getResources(), R.drawable.filter_lomo_map);
//        bitmaps[1] = BitmapFactory.decodeResource(context.getResources(), R.drawable.filter_vignette_map);
       bitmaps[0] =  ImageUtils.readBitMap(context, R.drawable.sierravignette22);
       bitmaps[1] =  ImageUtils.readBitMap(context, R.drawable.overlay_map);
       bitmaps[2] =  ImageUtils.readBitMap(context, R.drawable.filter_lomo_map);
    }

}
